﻿<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2008/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>spchol304_ex1_customerservice</Title>
      <Shortcut>spchol304_ex1_customerservice</Shortcut>
      <Description>Code snippet for SPCHOL304 Ex1 CustomerService.cs</Description>
      <Author>Microsoft Corporation</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp">
        <![CDATA[public static Dictionary<Int32, Customer> d = null;

        public static Customer ReadItem(Int32 id)
        {
            // take a copy for SharePoint
            Customer c = new Customer();
            Customer e = d[id];
            c.CustomerId = e.CustomerId;
            c.FirstName = e.FirstName;
            c.LastName = e.LastName;
            c.Message = e.Message;
            return c;
        }

        public static IEnumerable<Customer> ReadList()
        {
            // this is usually the first method called so check for null
            if (d == null)
            {
                d = new Dictionary<Int32, Customer>();
                for (int i = 0; i < 10; i++)
                {
                    Customer e = new Customer();
                    e.CustomerId = i;
                    e.Message = i + " Item Data";
                    e.FirstName = i + " First Name";
                    e.LastName = i + " Last Name";
                    d.Add(i, e);
                }
            }
            return d.Values;
        }

        public static void Update(Customer customer, Int32 id)
        {
            d[id].FirstName = customer.FirstName;
            d[id].LastName = customer.LastName;
            d[id].Message = customer.Message;
        }
]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
